// CSE571 - async-io-svc-handler.cpp          
// Authors: Jonathan Wald, Guangle Fan
// Abstract class which stores common functionality for svc handlers.

#include "async-io-svc-handler.h"
#include "globals.h"
#include <sstream>

const int TIMEOUT_VALUE = 2;

int AsyncIOSvcHandler::handle_completed_read(string) {
  return 0;
}

int AsyncIOSvcHandler::enqueue_string_for_output(string s) {
   int length = s.length() + 1; 
   ACE_Message_Block *mb = new ACE_Message_Block(length);
   mb->copy(s.c_str(), length);
   
   ACE_Time_Value tv(TIMEOUT_VALUE);
   putq(mb, &tv);
   ACE_Reactor::instance ()->mask_ops(this,
				      ACE_Event_Handler::WRITE_MASK,
				      ACE_Reactor::ADD_MASK);
   return 0;
}

int AsyncIOSvcHandler::enqueue_card_for_output(char s, char r) {
  stringstream stream;
  stream << s;
  stream << r;
  enqueue_string_for_output(stream.str());
  ACE_Reactor::instance ()->mask_ops(this,
                                     ACE_Event_Handler::WRITE_MASK,
                                     ACE_Reactor::ADD_MASK);
  return 0;
}
